package com.bk.controller;

import com.jfinal.kit.LogKit;
import com.jfinal.kit.StrKit;
import com.moomi.common.model.BkShop;
import com.moomi.common.model.BkUser;

public class BKShopController extends BKAuthController {

	@Override
	public void index() {
		super.index();
		setTitle("店铺日常管理");
		setAction("update");
		int shopId = getShopId();
		BkShop shop = BkShop.dao.findById(shopId);
		setInfoItem(shop);
		render("admin-form.html");
	}

	@Override
	public void update() {
		super.update();
		updateModel(BkShop.class);
		// String open = getPara("open");
		// String close = getPara("close");
		index();
	}

	public void changePassword() {
		String oldPassworld = getPara("oldPassworld");
		String password = getPara("password");
		if (StrKit.isBlank(password) || StrKit.isBlank(oldPassworld)) {
			LogKit.error("no password");
			renderMsg("未填写密码");
			return;
		}
		int userId = getUserId();
		BkUser bkUser = BkUser.dao.findById(userId);
		if (!oldPassworld.equals(bkUser.getPassword())) {
			// renderFailure();
			renderMsg("原密码错误");
			return;
		} else {
			bkUser.setPassword(password);
			System.out.println("bkUser.getPassword() 2" + bkUser.getPassword());

			boolean flag = bkUser.update();
			// renderFlag(flag);
			String text = flag ? "修改成功" : "修改失败";
			renderMsg(text);
		}

	}
}
